package com.zhejiangzhengyuan.municipal_common.mapper;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zhejiangzhengyuan.municipal_common.entity.Device;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zhejiangzhengyuan.municipal_common.entity.vo.DeviceVo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 物联网设备表，用于存储物联网监测设备数据 Mapper 接口
 *
 * @author linju
 * @since 2019-11-22
 */
@Repository
public interface DeviceMapper extends BaseMapper<Device> {

  @Update("update device set geometry=ST_GeomFromText('POINT(${lng} ${lat})') where id=#{id}")
  int updateGeometry(@Param("id") Long id, @Param("lng") String lng, @Param("lat") String lat);

  @Update(
      "update device set geometry=ST_GeomFromText('POINT(${lng} ${lat})'),geom_des=#{geoDes},geophysical_period = #{geophysical}  where name=#{name}")
  void updateGeoByName(
      @Param("name") String name,
      @Param("geoDes") String geoDes,
      @Param("geophysical") String geophysical,
      @Param("lng") String lng,
      @Param("lat") String lat);

  Page<DeviceVo> selectAllDevice(Page<DeviceVo> page, @Param("deviceType") String deviceType);

  @Select("select * from device where code = #{code} and type =#{type}")
  Device selectByCode(@Param("code") String code, @Param("type") String type);

  List<DeviceVo> selectWarnDevice(@Param("deviceType") String deviceType);

  int selectCountByDeviceId(@Param("deviceId") long deviceId, @Param("date") String date);

  int selectCountByTime(
      @Param("startTimestamp") String startTime, @Param("endTimestamp") String endTime);

  List<Device> getDetailAndLocationByType(@Param("type") String type);

  List<Device> getDetailAndLocationByLikeName(@Param("name") String name);
}
